package com.shop2cn.app.liveseller.testcase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.shop2cn.app.liveseller.parameter.*;
import com.shop2cn.app.liveseller.service.*;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.ymatou.iapi.godmch.parameter.setConditionMarkupConfigBean;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.LiveRoomShop2cnCallService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.livesellerShop2cn.*;
import com.ymttest.database.sqlwapper.livesellerShop2cn.LiveRoomShop2cnWapper;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;

/**
 * 添加商品到直播 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_AddProductsToLive {
	private static AddProductsToLiveBean addproductstoliveBean;
	private static AddProductsToLiveCall addproductstoliveCall;
	private static LiveRoomShop2cnWapper LiveRoomShop2cnWapper;
	private static int sellerId;
	private static String token;
	private static int csId;
	private static String cstoken;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("添加商品到直播");
		try {
			sellerId = GodmchManageCallService.CreateSellerMch();
			token = AuthCallServiceV2.createToken(sellerId, "app");
			csId = GodmchManageCallService.bindClientService(sellerId, 1);
			cstoken = AuthCallServiceV2.createToken(csId, "app");
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@Before
	public void caseUp() {
		addproductstoliveBean = new AddProductsToLiveBean();
		addproductstoliveCall = new AddProductsToLiveCall();
		LiveRoomShop2cnWapper = new LiveRoomShop2cnWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(addproductstoliveCall.getOpurl());
		LiveRoomShop2cnWapper = null;
	}

	@After
	public void caseDown() {

		Logger.end();
	}

	private void verifyDB(Integer liveid, String pid, Integer uid, Integer PutawayCount, Integer LiveProudctNum)
			throws Exception {
		List<Map> listm = LiveRoomShop2cnWapper.selectLiveproductByIdAndPid(liveid, pid);
		Logger.verifyEquals(1, listm.size(), "验证商品记录加入到数据库");
		Map pinfo = listm.get(0);
		Logger.verifyEquals(uid, pinfo.get("UserId"), "验证用户id");
		// 加入默认可售
		Logger.verifyEquals(1, pinfo.get("Status"), "验证Status");
		// 加入默认非置顶
		Logger.verifyEquals(false, pinfo.get("IsTop"), "验证IsTop");
		// 默认false
		Logger.verifyEquals(false, pinfo.get("linkword"), "验证linkword");
		LiveRoom liveroom = LiveRoomShop2cnWapper.selectLiveRoomById(liveid);
		Logger.verifyEquals(PutawayCount, liveroom.getPutawayCount(), "验证PutawayCount");
		Logger.verifyEquals(LiveProudctNum, liveroom.getLiveProductNum(), "验证LiveProductNum");
	}

	private void verifyDBRandHitNums(Integer liveid, List<String> pids, Integer uid, Integer PutawayCount,
			Integer LiveProudctNum) throws Exception {
		for (String pid : pids) {
			List<Map> listm = LiveRoomShop2cnWapper.selectLiveproductByIdAndPid(liveid, pid);
			Logger.verifyEquals(1, listm.size(), "验证商品记录加入到数据库");
			Map pinfo = listm.get(0);
			Logger.verifyEquals(uid, pinfo.get("UserId"), "验证用户id");
			// 加入默认可售
			Logger.verifyEquals(1, pinfo.get("Status"), "验证Status");
			// 默认RandHitNum为1或者0
			int pi = Integer.parseInt(pinfo.get("RandHitNum").toString());
			Logger.verifyEquals(true, pi == 1 || pi == 0, "验证RandHitNum默认为1或者0");
			// 加入默认非置顶
			Logger.verifyEquals(false, pinfo.get("IsTop"), "验证IsTop");
			// 默认false
			Logger.verifyEquals(false, pinfo.get("linkword"), "验证linkword");
			LiveRoom liveroom = LiveRoomShop2cnWapper.selectLiveRoomById(liveid);
			Logger.verifyEquals(PutawayCount, liveroom.getPutawayCount(), "验证PutawayCount");
			Logger.verifyEquals(LiveProudctNum, liveroom.getLiveProductNum(), "验证LiveProductNum");
		}
	}

	/**
	 * 验证是否是万能链
	 * 
	 * @param liveid
	 * @param pid
	 * @param uid
	 * @param PutawayCount
	 * @param LiveProudctNum
	 * @param isLinkword     是否是万能链 链接|专拍|直播专拍|直播专用|连接
	 * @throws Exception
	 */
	private void verifyDB(Integer liveid, String pid, Integer uid, Boolean isLinkword) throws Exception {
		List<Map> listm = LiveRoomShop2cnWapper.selectLiveproductByIdAndPid(liveid, pid);
		Logger.verifyEquals(1, listm.size(), "验证商品记录加入到数据库");
		Map pinfo = listm.get(0);
		Logger.debug(pinfo);
		Logger.verifyEquals(uid, pinfo.get("UserId"), "验证用户id");
		// 加入默认可售
		Logger.verifyEquals(1, pinfo.get("Status"), "验证Status");
		// 加入默认非置顶
		Logger.verifyEquals(false, pinfo.get("IsTop"), "验证IsTop");
		// 验证是否是万能链
		Logger.verifyEquals(isLinkword, pinfo.get("linkword"), "验证linkword");
		LiveRoom liveroom = LiveRoomShop2cnWapper.selectLiveRoomById(liveid);
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AddProductsToLive_001() {
		Logger.start(true, "添加商品到直播成功");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId,
					"autotest", false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService
					.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(), sellerId);

			addproductstoliveBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			addproductstoliveBean.setProductIdList(ProductIdList);
			addproductstoliveBean.setUserId(sellerId);
			addproductstoliveCall.setData(addproductstoliveBean);
			String head = "accesstoken=" + token;
			addproductstoliveCall.addHeader("ymt-pars", head);
			addproductstoliveCall.callService();
			Logger.verifyEquals("1", addproductstoliveCall.getString("SuccessCount"), "验证SuccessCount");
			Logger.verifyEquals("0", addproductstoliveCall.getString("FailCount"), "验证FailCount");
			verifyDB(createlive.getId(), pid, sellerId, 1, 1);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_AddProductsToLive_002() {
		Logger.start(true, "不输入liveid失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId,
					"autotest", false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService
					.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(), sellerId);

			// addproductstoliveBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			addproductstoliveBean.setProductIdList(ProductIdList);
			addproductstoliveBean.setUserId(sellerId);
			addproductstoliveCall.setData(addproductstoliveBean);
			String head = "accesstoken=" + token;
			addproductstoliveCall.addHeader("ymt-pars", head);
			addproductstoliveCall.callService();
			Logger.verifyEquals("400", addproductstoliveCall.getString("code"), "验证Code");
			Logger.verifyIsContains("直播Id参数错误", addproductstoliveCall.getString("msg"), "验证msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_AddProductsToLive_003() {
		Logger.start(true, "不输入token失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId,
					"autotest", false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService
					.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(), sellerId);

			addproductstoliveBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			addproductstoliveBean.setProductIdList(ProductIdList);
			// addproductstoliveBean.setUserId(sellerId);
			addproductstoliveCall.setData(addproductstoliveBean);

			addproductstoliveCall.callService();
			Logger.verifyEquals("400", addproductstoliveCall.getString("code"), "验证Code");
			Logger.verifyIsContains("请求头ymt-pars", addproductstoliveCall.getString("msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AddProductsToLive_004() {
		Logger.start(true, "liveid和userid不匹配失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId,
					"autotest", false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService
					.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(), sellerId);

			addproductstoliveBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			addproductstoliveBean.setProductIdList(ProductIdList);
			addproductstoliveCall.setData(addproductstoliveBean);
			int sellerId1 = GodmchManageCallService.CreateSellerMch();
			String token1 = AuthCallServiceV2.createToken(sellerId1, "app");
			String head = "accesstoken=" + token1;
			addproductstoliveCall.addHeader("ymt-pars", head);
			addproductstoliveCall.callService();
			Logger.verifyEquals("201", addproductstoliveCall.getString("code"), "验证Code");
			Logger.verifyIsContains("不合法", addproductstoliveCall.getString("msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_AddProductsToLive_005() {
		Logger.start(true, "不输入ProductId失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId,
					"autotest", false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService
					.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(), sellerId);

			addproductstoliveBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			// ProductIdList.add(pid);
			addproductstoliveBean.setProductIdList(ProductIdList);
			addproductstoliveBean.setUserId(sellerId);
			addproductstoliveCall.setData(addproductstoliveBean);
			String head = "accesstoken=" + token;
			addproductstoliveCall.addHeader("ymt-pars", head);
			addproductstoliveCall.callService();
			Logger.verifyEquals("400", addproductstoliveCall.getString("code"), "验证Code");
			Logger.verifyIsContains("必须选择至少一个商品", addproductstoliveCall.getString("msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AddProductsToLive_006() {
		Logger.start(true, "添加非本人商品到直播后查询直播列表不会显示");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId,
					"autotest", false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService
					.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(), sellerId);

			addproductstoliveBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			addproductstoliveBean.setProductIdList(ProductIdList);
			addproductstoliveCall.setData(addproductstoliveBean);
			int sellerId1 = GodmchManageCallService.CreateSellerMch();
			String token1 = AuthCallServiceV2.createToken(sellerId1, "app");
			String head = "accesstoken=" + token1;
			addproductstoliveCall.addHeader("ymt-pars", head);
			addproductstoliveCall.callService();
			Logger.verifyEquals("201", addproductstoliveCall.getString("code"), "验证Code");
			// TODO 这个商品不是这个用户的 添加查询查不出校验

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AddProductsToLive_007() {
		Logger.start(true, "添加不存在商品到直播后查询直播列表不会显示");
		try {
			LiveRoom createlive = LiveRoomShop2cnCallService
					.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(), sellerId);
			addproductstoliveBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add("-123");
			addproductstoliveBean.setProductIdList(ProductIdList);
			addproductstoliveBean.setUserId(createlive.getUserId());
			addproductstoliveCall.setData(addproductstoliveBean);
			String head = "accesstoken=" + token;
			addproductstoliveCall.addHeader("ymt-pars", head);
			addproductstoliveCall.callService();
			Logger.verifyEquals("0", addproductstoliveCall.getString("SuccessCount"), "验证SuccessCount");
			Logger.verifyEquals("1", addproductstoliveCall.getString("FailCount"), "验证FailCount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AddProductsToLive_009() {
		Logger.start(true, "status9直播推流结束添加商品失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId,
					"autotest", false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService
					.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(), sellerId);
			LiveRoomShop2cnWapper.updateLiveRoomPushStatus(createlive.getId(), 9);
			addproductstoliveBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			addproductstoliveBean.setProductIdList(ProductIdList);
			addproductstoliveBean.setUserId(sellerId);
			addproductstoliveCall.setData(addproductstoliveBean);
			String head = "accesstoken=" + token;
			addproductstoliveCall.addHeader("ymt-pars", head);
			addproductstoliveCall.callService();
			Logger.verifyEquals("201", addproductstoliveCall.getString("code"), "验证code");
			Logger.verifyEquals("直播已关闭或已结束", addproductstoliveCall.getString("msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AddProductsToLive_010() {
		Logger.start(true, "status7系统关闭添加商品失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId,
					"autotest", false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService
					.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(), sellerId);
			LiveRoomShop2cnWapper.updateLiveRoomPushStatus(createlive.getId(), 7);
			addproductstoliveBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			addproductstoliveBean.setProductIdList(ProductIdList);
			addproductstoliveBean.setUserId(sellerId);
			addproductstoliveCall.setData(addproductstoliveBean);
			String head = "accesstoken=" + token;
			addproductstoliveCall.addHeader("ymt-pars", head);
			addproductstoliveCall.callService();
			Logger.verifyEquals("201", addproductstoliveCall.getString("code"), "验证Code");
			Logger.verifyEquals("直播已关闭或已结束", addproductstoliveCall.getString("msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AddProductsToLive_011() {
		Logger.start(true, "status8未推流关闭直播添加商品失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId,
					"autotest", false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService
					.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(), sellerId);
			LiveRoomShop2cnWapper.updateLiveRoomPushStatus(createlive.getId(), 8);
			addproductstoliveBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			addproductstoliveBean.setProductIdList(ProductIdList);
			addproductstoliveBean.setUserId(sellerId);
			addproductstoliveCall.setData(addproductstoliveBean);
			String head = "accesstoken=" + token;
			addproductstoliveCall.addHeader("ymt-pars", head);
			addproductstoliveCall.callService();
			Logger.verifyEquals("201", addproductstoliveCall.getString("code"), "验证Code");
			Logger.verifyEquals("直播已关闭或已结束", addproductstoliveCall.getString("msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AddProductsToLive_012() {
		Logger.start(true, "status10运营关闭直播添加商品失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId,
					"autotest", false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService
					.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(), sellerId);
			LiveRoomShop2cnWapper.updateLiveRoomPushStatus(createlive.getId(), 10);
			addproductstoliveBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			addproductstoliveBean.setProductIdList(ProductIdList);
			addproductstoliveBean.setUserId(sellerId);
			addproductstoliveCall.setData(addproductstoliveBean);
			String head = "accesstoken=" + token;
			addproductstoliveCall.addHeader("ymt-pars", head);
			addproductstoliveCall.callService();
			Logger.verifyEquals("201", addproductstoliveCall.getString("code"), "验证Code");
			Logger.verifyEquals("直播已关闭或已结束", addproductstoliveCall.getString("msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AddProductsToLive_013() {
		Logger.start(true, "添加多个商品到直播成功");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId,
					"autotest", false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			AddAgentProductBean addAgentProductBean2 = AddAgentProductCallService.initAddAgentProductV2(sellerId,
					"autotest", false);
			String pid2 = AddAgentProductCallService.AddAgentProduct(addAgentProductBean2);
			Logger.comment("创建商品：" + pid2);
			LiveRoom createlive = LiveRoomShop2cnCallService
					.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(), sellerId);

			addproductstoliveBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			ProductIdList.add(pid2);
			addproductstoliveBean.setProductIdList(ProductIdList);
			addproductstoliveBean.setUserId(sellerId);
			addproductstoliveCall.setData(addproductstoliveBean);
			String head = "accesstoken=" + token;
			addproductstoliveCall.addHeader("ymt-pars", head);
			addproductstoliveCall.callService();
			Logger.verifyEquals("2", addproductstoliveCall.getString("SuccessCount"), "验证SuccessCount");
			Logger.verifyEquals("0", addproductstoliveCall.getString("FailCount"), "验证FailCount");
			for (String pids : ProductIdList) {
				verifyDB(createlive.getId(), pids, sellerId, ProductIdList.size(), ProductIdList.size());
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	// 耗时过长 手工执行
	public void Tc_AddProductsToLive_014() {
		Logger.start(true, "添加商品超限失败");
		try {
			List<String> ProductIdList = new ArrayList<>();
			int count = 51;
			for (int i = 0; i < count; i++) {
				AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId,
						"autotest", false);
				String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
				Logger.comment("创建商品：" + pid);

				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			LiveRoom createlive = LiveRoomShop2cnCallService
					.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(), sellerId);
			addproductstoliveBean.setLiveId(createlive.getId());
			addproductstoliveBean.setProductIdList(ProductIdList);
			addproductstoliveBean.setUserId(sellerId);
			addproductstoliveCall.setData(addproductstoliveBean);
			String head = "accesstoken=" + token;
			addproductstoliveCall.addHeader("ymt-pars", head);
			addproductstoliveCall.callService();
			Logger.verifyEquals("201", addproductstoliveCall.getString("code"), "验证Code");
			Logger.verifyEquals("待加入商品已超出直播商品上限", addproductstoliveCall.getString("msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	// 耗时过长 手工执行
	public void Tc_AddProductsToLive_015() {
		Logger.start(true, "多次添加商品超限失败");
		try {

			List<String> ProductIdList = new ArrayList<>();
			List<String> ProductIdList2 = new ArrayList<>();
			int count = 26;
			for (int i = 0; i < count; i++) {
				AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId,
						"autotest", false);
				String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}

			for (int i = 0; i < count; i++) {
				AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId,
						"autotest", false);
				String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
				Logger.comment("创建商品：" + pid);
				ProductIdList2.add(pid);
			}

			LiveRoom createlive = LiveRoomShop2cnCallService
					.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(), sellerId);
			addproductstoliveBean.setLiveId(createlive.getId());
			addproductstoliveBean.setProductIdList(ProductIdList);
			addproductstoliveBean.setUserId(sellerId);
			addproductstoliveCall.setData(addproductstoliveBean);
			String head = "accesstoken=" + token;
			addproductstoliveCall.addHeader("ymt-pars", head);
			addproductstoliveCall.callService();
			addproductstoliveBean.setProductIdList(ProductIdList2);
			addproductstoliveCall.callService();
			Logger.verifyEquals("201", addproductstoliveCall.getString("code"), "验证Code");
			Logger.verifyEquals("待加入商品已超出直播商品上限", addproductstoliveCall.getString("msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AddProductsToLive_016() {
		Logger.start(true, "重复添加商品到直播只会有1条记录");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId,
					"autotest", false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService
					.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(), sellerId);

			addproductstoliveBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			addproductstoliveBean.setProductIdList(ProductIdList);
			addproductstoliveBean.setUserId(sellerId);
			addproductstoliveCall.setData(addproductstoliveBean);
			String head = "accesstoken=" + token;
			addproductstoliveCall.addHeader("ymt-pars", head);
			addproductstoliveCall.callService();
			Logger.verifyEquals("1", addproductstoliveCall.getString("SuccessCount"), "验证SuccessCount");
			Logger.verifyEquals("0", addproductstoliveCall.getString("FailCount"), "验证FailCount");
			addproductstoliveCall.callService();
			Logger.verifyEquals("0", addproductstoliveCall.getString("SuccessCount"), "验证SuccessCount");
			Logger.verifyEquals("1", addproductstoliveCall.getString("FailCount"), "验证FailCount");
			verifyDB(createlive.getId(), pid, sellerId, 1, 1);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AddProductsToLive_018() {
		Logger.start(true, "快速添加商品到直播成功");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId,
					"autotest", false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService
					.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(), sellerId);

			addproductstoliveBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			addproductstoliveBean.setProductIdList(ProductIdList);
			addproductstoliveBean.setUserId(sellerId);
			addproductstoliveBean.setFastPublish(true);
			addproductstoliveCall.setData(addproductstoliveBean);
			String head = "accesstoken=" + token;
			addproductstoliveCall.addHeader("ymt-pars", head);
			addproductstoliveCall.callService();
			Logger.verifyEquals("1", addproductstoliveCall.getString("SuccessCount"), "验证SuccessCount");
			Logger.verifyEquals("0", addproductstoliveCall.getString("FailCount"), "验证FailCount");
			verifyDB(createlive.getId(), pid, sellerId, 1, 1);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AddProductsToLive_019() {
		Logger.start(true, "添加商品到直播成功,商品落库时增加字段RandHitNum作为流量基数");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId,
					"autotest", false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService
					.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(), sellerId);

			addproductstoliveBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			addproductstoliveBean.setProductIdList(ProductIdList);
			addproductstoliveBean.setUserId(sellerId);
			addproductstoliveCall.setData(addproductstoliveBean);
			String head = "accesstoken=" + token;
			addproductstoliveCall.addHeader("ymt-pars", head);
			addproductstoliveCall.callService();
			Logger.verifyEquals("1", addproductstoliveCall.getString("SuccessCount"), "验证SuccessCount");
			Logger.verifyEquals("0", addproductstoliveCall.getString("FailCount"), "验证FailCount");
			Thread.sleep(2000);
			verifyDBRandHitNums(createlive.getId(), Arrays.asList(pid), sellerId, 1, 1);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AddProductsToLive_020() {
		Logger.start(true, "添加多个商品到直播成功,商品落库时增加字段RandHitNum作为流量基数");
		try {

			List<String> ProductIdList = new ArrayList<>();
			Integer count = 10;
			for (int i = 0; i < count; i++) {
				AddAgentProductBean addAgentProductBean2 = AddAgentProductCallService.initAddAgentProductV2(sellerId,
						"autotest", false);
				String pid2 = AddAgentProductCallService.AddAgentProduct(addAgentProductBean2);
				Logger.comment("创建商品：" + pid2);
				ProductIdList.add(pid2);
				Thread.sleep(500);
			}
			LiveRoom createlive = LiveRoomShop2cnCallService
					.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(), sellerId);

			addproductstoliveBean.setLiveId(createlive.getId());
			addproductstoliveBean.setProductIdList(ProductIdList);
			addproductstoliveBean.setUserId(sellerId);
			addproductstoliveCall.setData(addproductstoliveBean);
			String head = "accesstoken=" + token;
			addproductstoliveCall.addHeader("ymt-pars", head);
			addproductstoliveCall.callService();
			Logger.verifyEquals(count.toString(), addproductstoliveCall.getString("SuccessCount"), "验证SuccessCount");
			Thread.sleep(2000);
			verifyDBRandHitNums(createlive.getId(), ProductIdList, sellerId, count, count);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AddProductsToLive_021() {
		Logger.start(true, "客服添加商品到直播成功");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId,
					"autotest", false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomShop2cnCallService
					.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(), sellerId);

			addproductstoliveBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			addproductstoliveBean.setProductIdList(ProductIdList);
//			addproductstoliveBean.setUserId(sellerId);
			addproductstoliveCall.setData(addproductstoliveBean);
			String head = "accesstoken=" + cstoken;
			addproductstoliveCall.addHeader("ymt-pars", head);
			addproductstoliveCall.callService();
			Logger.verifyEquals("1", addproductstoliveCall.getString("SuccessCount"), "验证SuccessCount");
			Logger.verifyEquals("0", addproductstoliveCall.getString("FailCount"), "验证FailCount");
			verifyDB(createlive.getId(), pid, sellerId, 1, 1);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AddProductsToLive_022() {
		Logger.start(true, "添加商品到直播成功-直播继承自动铺货");
		try {
			Integer sellerId2 = GodmchManageCallService.CreateSellerMch();
			String token2 = AuthCallServiceV2.createToken(sellerId2, "app");
			Integer mchId_Agent = GodmchManageCallService.createAgent(sellerId2);
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProductV2(sellerId2,
					"autotest", false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Logger.comment("创建商品：" + pid);
			//设置自动加价
			setConditionMarkupConfigBean setConditionMarkupConfigBean = GodmchManageCallService
					.initDefSetConditionMarkupConfig(mchId_Agent, sellerId2, 1, addAgentProductBean, 0);
			setConditionMarkupConfigBean.setRefreshProduct(true);
			GodmchManageCallService.SetConditionMarkupConfigCall(setConditionMarkupConfigBean);

			CreateSellerLiveBean c = LiveRoomShop2cnCallService.initCreatesellerliveBean();
			c.getLiveDto().setLiveInherit(true);
			LiveRoom createlive = LiveRoomShop2cnCallService.CreateSellerLive(c, sellerId2);
			LiveRoomShop2cnCallService.AddLiveToShop(createlive.getId(), mchId_Agent, sellerId2);

			addproductstoliveBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			addproductstoliveBean.setProductIdList(ProductIdList);
			addproductstoliveBean.setUserId(sellerId2);
			addproductstoliveCall.setData(addproductstoliveBean);
			String head = "accesstoken=" + token2;
			addproductstoliveCall.addHeader("ymt-pars", head);
			addproductstoliveCall.callService();
			Logger.verifyEquals("1", addproductstoliveCall.getString("SuccessCount"), "验证SuccessCount");
			Logger.verifyEquals("0", addproductstoliveCall.getString("FailCount"), "验证FailCount");
			verifyDB(createlive.getId(), pid, sellerId2, 1, 1);
			// 验证发送铺货消息
			MessageListBean MessageListBean = MqQueryCallService.initImportAgentproduct(pid, mchId_Agent);
			List<Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if (joa.size() == 0) {
				Thread.sleep(5000);
				joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele -> {
				Logger.debug(ele.toString());
			});
			Logger.verifyEquals(joa.size() >= 1, true, "回调了自动导入" + MessageListBean.toString());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}